﻿using System;
using Entity;
using BLL;
using BLL.Access;
using System.Data;
using Web.Class;

namespace Web.Pages.YongShui._13.LAIHANGL
{
    public partial class jiHuaZYXXXX : BasePage
    {
        #region 属性

        #endregion

        #region 变量
        /// <summary>
        /// 访问来函表
        /// </summary>
        YS_LH_LAIHANXXProcess blllh = new YS_LH_LAIHANXXProcess();
        /// <summary>
        /// 来函用户信息
        /// </summary>
        YS_LH_YONGHUXXProcess laihanyhxx = new YS_LH_YONGHUXXProcess();

        /// <summary>
        /// 访问数据库
        /// </summary>
        SpHelper _sphelper = new SpHelper();
        /// <summary>
        /// 来函计划转移表
        /// </summary>
        YS_LH_JIHUAZYProcess bllzyjh = new YS_LH_JIHUAZYProcess();

        /// <summary>
        /// 流程表
        /// </summary>
        YS_LH_LAIHANLCJLBLL lcbll = new YS_LH_LAIHANLCJLBLL();
        #endregion

        #region 事件
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 页面孔家加载完全后绑定值
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoadComplete(EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        #endregion

        #region 方法

        private void BindData()
        {
            if (string.IsNullOrEmpty(Request["id"]) || Request["id"] == "null")
            {
                return;
            }
            int id = Convert.ToInt32(Request["id"]);
            YS_LH_LAIHANXX laihan = blllh.SelectYS_LH_LAIHANXX(id);

            if (laihan != null)
            {
                UCLHLCSHENPIYIJIANS.LoadInfo(laihan);
                h_laihan.Value = laihan.S_LAIHANBH;
                h_yonghu.Value = laihan.S_YONGHUBH;
                string Jyonghu = laihan.S_YONGHUBH;
                string Yyonghu = "";
                string where = " S_LAIHANBH='{0}' and S_YONGHUBHJ='{1}' and I_LIUCHENGBH=1 ";
                where = string.Format(where, laihan.S_LAIHANBH, laihan.S_YONGHUBH);
                DataTable JiHuaZY = bllzyjh.SelectYS_LH_JIHUAZiesDynamic(where, "", null);
                if (JiHuaZY != null && JiHuaZY.Rows.Count > 0)
                {
                    Yyonghu = JiHuaZY.Rows[0]["S_YONGHUBHY"].ToString();
                }
                else
                {
                    PageTools.AlertMsg(this, "相关来函信息不存在");
                    return;
                }
                DataTable dtZhanDian = BusinessTool.GetTextAndValue("View_AS_UserInfo", "ZHANDIANBH", "ROLEID", null, string.Format("USERID={0}", LoginInfo.CurrentUser.UserID)).Tables[0];
                string zhandian = dtZhanDian.Rows[0]["TEXT"].ToString();//站点
                string roleid = dtZhanDian.Rows[0]["VALUE"].ToString();//9001 业务员，3001 办事处主任
                txtLiYou.Text = laihan.S_SHENQINGLY;
                UCLHJiHuaZYUserInfo.LoadInfo(Jyonghu, Yyonghu, laihan);
               
                UCLHJiHuaZYUserInfo.SetShouLiStatus();

                DataSet jhxx = _sphelper.P_YS_LH_JIHUAZY_CX(Jyonghu, Yyonghu, Convert.ToInt32(JiHuaZY.Rows[0]["I_Y"]), JiHuaZY.Rows[0]["S_ZHANDIANBH"].ToString());
                //DataTable dt = jhxx.Tables[0];
                DataTable olddt = jhxx.Tables[0];
                DataTable dt = olddt.Clone();
                if (olddt != null && olddt.Rows.Count > 0)
                {
                    foreach (DataRow dr in olddt.Rows)
                    {
                        if (roleid == "9001")
                        {
                            if (Convert.ToInt32(dr["I_LIUCHENGBH"]) <= 3)
                            {
                                DataRow newdr = dt.NewRow();
                                foreach (DataColumn d in olddt.Columns)
                                {
                                    newdr[d.ColumnName] = dr[d.ColumnName];
                                }
                                dt.Rows.Add(newdr);
                            }

                        }
                        else
                        if (roleid == "3001")
                        {
                            if (Convert.ToInt32(dr["I_LIUCHENGBH"]) <= 4)
                            {
                                DataRow newdr = dt.NewRow();
                                foreach (DataColumn d in olddt.Columns)
                                {
                                    newdr[d.ColumnName] = dr[d.ColumnName];
                                }
                                dt.Rows.Add(newdr);
                            }

                        }
                        else
                        if (roleid == "2001")
                        {
                            if (Convert.ToInt32(dr["I_LIUCHENGBH"]) <= 5)
                            {
                                DataRow newdr = dt.NewRow();
                                foreach (DataColumn d in olddt.Columns)
                                {
                                    newdr[d.ColumnName] = dr[d.ColumnName];
                                }
                                dt.Rows.Add(newdr);
                            }

                        }
                        else if (roleid == "2003")
                        {
                            if (Convert.ToInt32(dr["I_LIUCHENGBH"]) <= 6)
                            {
                                DataRow newdr = dt.NewRow();
                                foreach (DataColumn d in olddt.Columns)
                                {
                                    newdr[d.ColumnName] = dr[d.ColumnName];
                                }
                                dt.Rows.Add(newdr);
                            }

                        }
                        else if (roleid == "1001"||Convert.ToInt32(roleid)>9001)
                        {
                            DataRow newdr = dt.NewRow();
                            foreach (DataColumn d in olddt.Columns)
                            {
                                newdr[d.ColumnName] = dr[d.ColumnName];
                            }
                            dt.Rows.Add(newdr);
                        }
                    }
                }
                if (dt != null && dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (Convert.ToInt32(dr["I_LIUCHENGBH"]) == 3)
                        {
                            //txtYeWuY.Text = dr["S_SHENPIYJ"].ToString();
                        }
                        else if (Convert.ToInt32(dr["I_LIUCHENGBH"]) == 4)
                        {
                            //txtZhuRen.Text = dr["S_SHENPIYJ"].ToString();
                        }
                        else if (Convert.ToInt32(dr["I_LIUCHENGBH"]) == 5)
                        {
                            //txtJieShui.Text = dr["S_SHENPIYJ"].ToString();
                        }
                        else if (Convert.ToInt32(dr["I_LIUCHENGBH"]) == 6)
                        {
                            //txtJiCai.Text = dr["S_SHENPIYJ"].ToString();
                        }
                        else if (Convert.ToInt32(dr["I_LIUCHENGBH"]) == 7)
                        {
                            //txtChuZhang.Text = dr["S_SHENPIYJ"].ToString();
                        }
                        

                    }
                }
                Repeater1.DataSource = dt;
                Repeater1.DataBind();
            }
            else
            {
                PageTools.AlertMsg(this, "相关来函信息不存在");
                return;
            }


        }
        
        
        #endregion

    }
}